package chapter14.section2;

//程序14-4：JRaidoButton的使用

import javax.swing.*;

public class RadioDemo extends JFrame {
    public RadioDemo(String title, int width, int height) {
        super(title);
        this.setSize(width, height);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setContentPane(new JPanel());
        init();
    }

    public static void main(String[] args) {
        RadioDemo app = new RadioDemo("RadioDemo", 600, 400);
        app.setVisible(true);
    }

    private void init() {
        JRadioButton rdb1 = new JRadioButton("rdb1");
        JRadioButton rdb2 = new JRadioButton("rdb2");
        JRadioButton rdb3 = new JRadioButton("rdb3");
        // 下面将三个按钮加入到一个组中，而剩余两个没有加入
        ButtonGroup bg = new ButtonGroup();
        bg.add(rdb1);
        bg.add(rdb2);
        bg.add(rdb3);
        JRadioButton rdb4 = new JRadioButton("rdb4");
        JRadioButton rdb5 = new JRadioButton("rdb5");
        // 每个按钮依然需要添加到内容窗格中，ButtonGroup不是一个组件类
        this.add(rdb1);
        this.add(rdb2);
        this.add(rdb3);
        this.add(rdb4);
        this.add(rdb5);
    }
}